﻿Ext.define('Twi.Tbar', {
    statics: {
        Query: function (text, handler,width) {
            handler = (typeof handler == "function") ? handler : Ext.emptyFn;
            var toolbarItem = [{
                xtype: 'label',
                text: text || '名称：'
            }, {
                xtype: 'textfield',
                itemId: 'txtContent',
                width: width||120,
                listeners:
			    {
			        specialkey: function (field, e) {
			            if (e.getKey() == e.ENTER) {
			                handler();
			            }
			        }
			    }
            }, {
                text: '查询',
                tooltip: '查询',
                iconCls: 'ico_search',
                handler: handler
            }];
            return toolbarItem;
        } //end TbarQuery

        , New: function (handler, disable, isSeparatorAfter) {
            var toolbarItem = [];
            toolbarItem.push(Ext.create('Ext.Action', {
                text: '新增',
                tooltip: '新增',
                iconCls: 'ico_add',
                disabled: Ext.isBoolean(disable) ? disable : false,
                handler: (typeof handler == 'function') ? handler : Ext.emptyFn
            }));
            //isSeparatorAfter = isSeparatorAfter || true;
            if (isSeparatorAfter != false) {
                isSeparatorAfter = true;
            }
            if (isSeparatorAfter) {
                //toolbarItem.push(Ext.create('Ext.toolbar.Separator'));
                toolbarItem.push('-');
            }
            return toolbarItem;
        }

        , Edit: function (handler, disable, isSeparatorAfter) {
            var toolbarItem = [];
            toolbarItem.push(Ext.create('Ext.Action', {
                text: '编辑',
                tooltip: '编辑',
                iconCls: 'ico_modify',
                disabled: Ext.isBoolean(disable) ? disable : false,
                handler: (typeof handler == 'function') ? handler : Ext.emptyFn
            }));
            //isSeparatorAfter = isSeparatorAfter || true;
            if (isSeparatorAfter != false) {
                isSeparatorAfter = true;
            }
            if (isSeparatorAfter) {
                //toolbarItem.push(Ext.create('Ext.toolbar.Separator'));
                toolbarItem.push('-');
            }
            return toolbarItem;
        }

        , Delete: function (handler, disable, isSeparatorAfter) {
            var toolbarItem = [];
            toolbarItem.push(Ext.create('Ext.Action', {
                text: '删除',
                tooltip: '删除',
                iconCls: 'ico_delete',
                disabled: Ext.isBoolean(disable) ? disable : false,
                handler: (typeof handler == 'function') ? handler : Ext.emptyFn
            }));
            //isSeparatorAfter = isSeparatorAfter || true;
            if (isSeparatorAfter != false) {
                isSeparatorAfter = true;
            }
            if (isSeparatorAfter) {
                //toolbarItem.push(Ext.create('Ext.toolbar.Separator'));
                toolbarItem.push('-');
            }
            return toolbarItem;
        }

        , Refresh: function (handler) {
            return Ext.create('Ext.Action', {
                text: '刷新',
                tooltip: '刷新',
                iconCls: 'ico_refresh',
                handler: (typeof handler == 'function') ? handler : Ext.emptyFn
            });
        }

        , Separator: function () {
            return Ext.create('Ext.toolbar.Separator');
        }

        , Fill: function () {
            return Ext.create('Ext.toolbar.Fill');
        }

        , CRUD: function (addFn, editFn, delFn, refreshFn, isSeparatorAfter) {
            addFn = (typeof addFn == "function") ? addFn : Ext.emptyFn;
            editFn = (typeof editFn == "function") ? editFn : Ext.emptyFn;
            delFn = (typeof delFn == "function") ? delFn : Ext.emptyFn;
            refreshFn = (typeof refreshFn == "function") ? refreshFn : Ext.emptyFn;
            //isSeparatorAfter = isSeparatorAfter || true;
            if (isSeparatorAfter != false) {
                isSeparatorAfter = true;
            }
            var toolbarItem = [];
            toolbarItem = toolbarItem.concat(this.New(addFn, false, isSeparatorAfter), this.Edit(editFn, false, isSeparatorAfter), this.Delete(delFn, false, isSeparatorAfter), this.Refresh(refreshFn));
            //toolbarItem.push(this.New(addFn, false, true));
            //toolbarItem.push(this.Edit(editFn, false, true));
            //toolbarItem.push(this.Delete(delFn, false, true));
            //toolbarItem.push(this.Refresh(refreshFn));
            return toolbarItem;
        } //end CRUD
    }
});

